/*#################################################

Tooltip | v1.0
Max Felker | max@bigroomstudios.com

Creates tooltips

#################################################*/

var Tooltip = Class.create({

	initialize: function(config) {

		this.target = config.target;
		this.title = this.target.title;
		this.target.title = '';
		this.container = Builder.node('div',{ id:this.target.id+"-tool-tip",className:'tool-tip',style:'display:none;'});

		this.target.on('mouseenter',this.show_tooltip.bind(this));
		this.target.on('mouseleave',this.hide_tooltip.bind(this));  
		
		document.body.appendChild(this.container);  
		
		live.tooltips.set(this.target.id+"-tool-tip",this);	

  },
  
  position: function() {
  
  	if(!live.mouse){
  		return false;
  	}
  
  	this.container.setStyle({
  		top: live.mouse.y+20+'px',
  		left: live.mouse.x+'px'
  	});
  	 
  },
  
  show_tooltip: function(event) {

	this.handler = this.position.bind(this);
	
	document.on('mousemove', this.handler);

  	this.container.update(this.title);
  	
  	this.container.show();
  
  },
  
  hide_tooltip: function() {
  
  	Event.stopObserving(document, 'mousemove', this.handler);
  
  	this.container.hide();
  
  }
  
});

document.on('dom:loaded', function() {

	$$('.tool-tip-target').each(function(target) {
		if(target) {
			new Tooltip({target:target});
		}
	});
	
});
